"""### 【资源类】Resource 服务端开发"""

#导入mcp服务端依赖包
from mcp.server import FastMCP

#创建MCP服务端实例
mcp = FastMCP("Resource MCP Server")

#定义资源类
@mcp.resource(
    uri="file:///fetch_book.txt",
    name="fetch_book",
    description="获取图书信息",
    mime_type="text/plain",
)
def fetch_book_resource():
    """
    读取本地文件books.txt
    """
    print("==请求资源：fetch_book_resource")
    with open("books.txt", "r", encoding="utf-8") as file:
        return file.read()


if __name__ == "__main__":
    print("Resource资源 ---> MCP Server is running...")
    #启动服务
    mcp.run(transport="sse")